﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MVCMamage.DAL;
using MVCManage.Model;
using MVCManage.Model.Base;
namespace MVCManage.BLL
{
    public class YhBLL : BaseBLL<Users>
    {
      
        public override void SetDal()
        {
            base.Dal = new YhDAL();
        }

        public List<Users> UserList(string name,int page,int limit,out int count) {
            var zhi = Dal.Query();
            if (!string.IsNullOrWhiteSpace(name)) {
                zhi = zhi.Where(n=>n.userName.Contains(name));
            }
            count = zhi.Count();
            var pagelist = zhi.OrderBy(n => n.userID).Skip((page - 1) * limit).Take(limit);
            return pagelist.ToList();
        }
        public List<Users> VipList(string name,int page,int limit,out int count)
        {
            var zhi = Dal.Query().Where(n => n.Roles.roleID == 6);
            if (!string.IsNullOrWhiteSpace(name))
            {
                zhi=zhi.Where(n=> n.userName.Contains(name));
            }
            count = zhi.Count();
            var pagelist=zhi.OrderBy(n=>n.userID).Skip((page -1) * limit).Take(limit);
            return pagelist.ToList();
        }

        public bool Delete(int id) {
            var zhi = Dal.Query().Where(n => n.userID == id).FirstOrDefault();
            Dal.Delete(zhi);
            return Dal.SaveChanges();
        }
        public bool Deletes(int[] ids)
        {
            var zhi = Dal.Query().Where(n =>ids.Contains(n.userID)).ToList();
            Dal.Deletes(zhi);
            return Dal.SaveChanges();
        }
    }
}
